{extend name="public:base" /}

{block name="jquery"}
<script src="__PUBLIC__/jquery-weui/dist/lib/jquery-2.1.4.js"></script>
{/block}  

{block name="head"}
<link href="__PUBLIC__/view_res/mobile/css/cart.css" type="text/css" rel="Stylesheet" />
<link href="__PUBLIC__/jquery-weui/dist/lib/weui.min.css" type="text/css" rel="Stylesheet" />
<link href="__PUBLIC__/jquery-weui/dist/css/jquery-weui.min.css" type="text/css" rel="Stylesheet" />
<script src="__PUBLIC__/jquery-weui/dist/lib/fastclick.js"></script>
<script src="__PUBLIC__/jquery-weui/dist/js/jquery-weui.min.js"></script>
<script src="__PUBLIC__/jquery-weui/dist/js/city-picker.js"></script>
<script src="__PUBLIC__/js/jquery/jquery-migrate-1.2.1.min.js"></script>
<script src="__PUBLIC__/artTemplate/template.js"></script>
<script src="__PUBLIC__/view_res/mobile/load_list.js"></script>

<link href="__PUBLIC__/view_res/mobile/css/uc.css" type="text/css" rel="Stylesheet" />
<style>
	body {  background: #f7f7f7;  }
	.productCount {
		border: none;
		/*width: 60px;*/
	}
</style>
{/block} 
{block name="header"}
{include file="public/top-nav" /}
{/block}

{block name="content"}

<input type="hidden" id="weight" value="{$weight}" />{//重量}
<input type="hidden" id="shipping" value="{$shipping|default=''}" />{//是否需要配送}
<input type="hidden" id="city_id" value="{$address.city_id|default=''}" />{//配送的城市}
<input type="hidden" id="address_id" value="{$address.address_id|default=''}" />{//配送的地址}
{if condition="count($goods) neq 0"}
<input type="hidden" id="type" name="type" value="{$goods[0]['type']}" />{//商品属性}
<input type="hidden" id="goods_id" name="goods_id" value="{$goods[0]['goods_id']}" />{//商品id}
{/if}
<!-- 收货地址 start -->
{if condition="!empty($goods)"}
	{if condition="$shipping"}
		<div id="shipping_box">
			<div id="addrPick"></div>
			<header class="Thead">收货信息</header>
			<div id="express-bar"></div>
			<div id="express_address">	
			{if condition="isset($address)"}   
			<div class="express-person-info clearfix">
			    <div class="express-person-name">
			        <span id="express-name">{$address.name|default=''}</span><span id="express-person-phone">{$address.telephone|default=''}</span>
			    </div>
			</div>
			<div class="express-address-info">
			    <span  id="express-address">{$address.address|default=''}</span>
			</div>
			{else/}
				<div id="wrp-btn">点击选择收货地址</div>
				<div class="express-person-info clearfix">
			    <div class="express-person-name">
			        <span id="express-name"></span><span id="express-person-phone"></span>
			    </div>
			</div>
			<div class="express-address-info">
			    <span id="express-address"></span>
			</div>
			{/if}
			</div>
		</div>
	{/if}
{/if}	
<!-- 收货地址 end -->

<header class="Thead">订单信息</header>

<div id="orderDetailsWrapper" data-minheight="68px">
	
	{if condition="!empty($goods)"}
	{volist name="goods" id="d"}
	<section class="cartListWrap clearfix" id="goods{$d.cart_id}">
	
    <a href="{:url('goods/detail',array('id'=>$d.goods_id))}"><img alt="{$d.name}"  src="IMG_ROOT{$d.image}" /></a>
    
    <div class="cartListDesc">
        <p class="title">
            <a style="color:#000;" href="{:url('goods/detail',array('id'=>$d.goods_id))}">{$d.name}</a>
        </p>
        <p class="count">
        	{if condition="$d['shipping'] eq 0"}
        	<span class="spec Elipsis" style="border:1px solid #f60;color:#f60;">免配送</span><br />
        	{/if}
            <span class="spec Elipsis">
              
                {volist name="$d['option']" id="option"}	
				<small>{$option.name}:{$option.value}</small><br />
				{/volist}
				
            </span>
            
            <span class="dprice prices" id="prices{$d.cart_id}">价格：{$d.price|round=2}	</span>
        </p>
		<p class="count">
			<span class="dprice points" id="points{$d.cart_id}">赠送积分：{$d.points|round=2}	</span>

		</p>
       
        <!--<dl id="select_number{$d.cart_id}" class="pd-dsc clearfix">
            <dt class="productCount clearfix">
            <a onclick='changeQty(0,"{$d.goods_id}","{$d.cart_id}","{$d.cart_id}"); return false;' class="btn productCountMinus" ></a>
            <span class="productCountNum"><input  onkeyup='change_quantity("{$d.goods_id}",this,"{$d.cart_id}","{$d.cart_id}");' minimum='{$d.minimum}' id="quantity{$d.cart_id}" size="5" type='text' value='{$d.quantity}' class="dcount productCountNumi" /></span>
            <a onclick='changeQty(1,"{$d.goods_id}","{$d.cart_id}","{$d.cart_id}"); return false;' class="btn productCountPlus" ></a>
            </dt>
        </dl>-->
		
			
        <!--<a class='cartDelbtn' cart_id='{$d.cart_id}'></a>-->
    </div>
	</section>
	{/volist}
	{else/}
		
			<div id="cartnothing" onclick="location='{:url("/mobile")}'">购物车空空如也，去逛逛吧</div>
		
	{/if}
</div>



{if condition="!empty($goods)"}		
		<section class="orderopt inp" id="beizhu">
            <span class="label">订单备注</span>
            <input type="text" class="Elipsis" value="" id="comment" name="comment" id="input-remark" placeholder="选填，可填写您的特殊要求" />
        </section>
		<header class="Thead">支付方式</header>

		<section class="orderopt inp" id="beizhu">
			<div style="width: 60%;margin-left: 20%">
				<label for="card">
					通证消费
					<input type="radio" checked id="card" class="apply" value="1" name="apply" />
				</label>
				&nbsp;&nbsp;&nbsp;
				<label for="integrals">
					消费积分消费
					<input type="radio" id="integrals" class="apply" value="2" name="apply"/>
				</label>
			</div>

		</section>

<!-- 订单总额 -->
        <div id="orderSummay">
        
	            {if condition="$shipping"}		           
			            <div>
			                运费 :
			                	 {if condition="$transport"}
			                		<b class="prices"></b> <b class="prices font13" id="order_yunfei">  {$transport}</b>
			                	{else/}
			                		<b class="prices"></b><b class="prices font13" id="order_yunfei">免运费</b>	
			                	{/if}	
			             
			            </div>
						

			            <div>
			                总计价格 : <b class="prices"> </b> <b class="prices last" id="order_amount">{$total_price+$transport}</b>
			            </div>	            
	            {else/}
			            <div>
			                总计 : <b class="prices"> 价格</b> <b class="prices last" id="order_amount">{$total_price}</b>
			            </div>
	            {/if}
	       
            
        </div>
	
	
      
	     <div class="weui_btn_area">
				   <a class="weui_btn weui_btn_primary payment" id="predeposit-payment-btn" style="background: #e54245;">立即购买</a>
		</div>	       

       
{/if}

{//*************手机版 收货地址  START  *************}
{include file="cart/address" /}
{//*************手机版 END  *************}


{/block}

{block name="script"}
<script>
<?php if(isset($error)){ ?>
	$.toast.prototype.defaults.duration='4000';
	$.toast('<?php echo $error; ?>', "forbidden");
<?php } ?>



$('#predeposit-payment-btn').click(function(){
	
	var city_id=$('#city_id').val();
	var address_id=$('#address_id').val();
	var comment=$('#comment').val();
	var type=$('#type').val();
	var goods_id=$('#goods_id').val();
	var apply = $('input:radio:checked').val();

	var f=confirm('确认购买吗？');
	if(f==false){
		return false;
	}

	$.showLoading();

	$.post(
		'{:url("predeposit/pay")}',
		{
			city_id:city_id,
			comment:comment,
			address_id:address_id,
			goods_id:goods_id,
			apply:apply,
			type:type
		},
		function(d){
			$.hideLoading();
			if(d.error){
				$.toast(d.error, "forbidden");
			}
			
			if(d.success){
				$.toast(d.success);
				
				setTimeout(function (){
			      location='{:url("user/index")}';
			    }, 500);
			
			}
		}
	);
	
});

function change_quantity(goods_id,input,cart_id,key){
	var qty=parseFloat(input.value);	
	
	var min=$(input).attr('minimum');	
	
	if(qty<min){		
		$.toast('最小起订量是'+min,"forbidden");
		qty=min;
	}
	
	update_cart(goods_id,qty,cart_id,key);
}
/***更新数量 start*****/
function changeQty(increase,goods_id,cart_id,key) {
    var qty = parseFloat($('#quantity' + key).val()); 

    if ( !isNaN(qty) ) {
    	//增加
		if(increase){			
			update_cart(goods_id,(qty+1),cart_id,key);
		}else{
			update_cart(goods_id,(qty-1),cart_id,key);
		}     
    }
}	
{/* id:商品id,qty:数量,cart_id:购物车id,key:用于选择标签 */}
function update_cart(id,qty,cart_id,key){
	
	var city_id=$('#city_id').val();

	$.post(
		'{:url("cart/update")}',
		{id:id,q:qty,cart_id:cart_id,city_id:city_id},
		function(json){
			
			if(json.error){
		
				$.toast(json.error,"forbidden");
				if(json.url){
					setTimeout(function (){
				        location.href=json.url;
				    }, 1000);
				}
				if(json.minimum){
					$('#quantity' + key).val(json.minimum);	
				}
			}else{
				$('#quantity' + key).val(qty);		
					
				$('#prices' + key).text('价格'+json['price']);
				
				$('#order_amount_sig').text(json['total_all_price']);
				
				$('#order_amount').text((parseFloat(json.total_all_price)+parseFloat(json.transport)).toFixed(2));
				
				if(json['transport']!='0'){
					$('#order_yunfei').text('¥ '+json['transport']);
				}else{
					$('#order_yunfei').text('免运费');
				}
				
				
				$('#weight').val(json['weight']);
			}
		}
	);
}
/***更新数量 end *****/

/***删除 *****/
$('.cartDelbtn').click(function(){
	
	var key=$(this).attr('cart_id');
	var city_id=$('#city_id').val();
	
	$.showLoading();
	
	$.post(
		"{:url('cart/remove')}",
		{
		cart_id:key,
		city_id:city_id,			
		},
		function(json){
			
			if(json.error){
			
				$.toast(json.error,"forbidden");
				if(json.url){
					setTimeout(function (){
				        location.href=json.url;
				    }, 1000);
				}
				
				return;
			}
			
			$('#goods'+key).remove();
			
			if (json['total_num']!=0) {	
								
					if(city_id== ''){						
						
						$('.last').text(json['total_all_price']);
						
						$('#weight').val(json['weight']);
					}else{							
						//总价
						$('#order_amount_sig').text(json['total_all_price']);
						
						if(json['transport']){
							//总计
							$('#order_amount').text((parseFloat(json.total_all_price)+parseFloat(json.transport)).toFixed(2));
							//运费
							$('#order_yunfei').text(json['transport']);
						}else{
							//免配送的
							//总计
							$('#order_amount').text((parseFloat(json.total_all_price)+parseFloat(0)).toFixed(2));
							//运费
							$('#order_yunfei').text(0);
							$('#shipping_box').remove();
							
							$('#city_id').val('');
							$('#address_id').val('');
						}
						
						$('#weight').val(json['weight']);
					}
				
				
			}else if(json['total_num']==0){
				
				$('#orderDetailsWrapper').append('<div id="cartnothing" onclick="location=\'{:url("/mobile")}\'">购物车空空如也，去逛逛吧</div>');	
				
				$('#beizhu').remove();
				$('#shipping_box').remove();
				$('#orderSummay').remove();
				$('.weui_btn_area').remove();
			}
			
			
			
		}
		
	);
	
	setTimeout(function (){
        $.hideLoading();
    }, 500);
	
});



</script>

{include file="cart/wxpay" /}

{/block}



